import connect2
import myImageViewer
import vtk
import pythonRegistration as pr

reload(pr)

#Setup Registration class
reg=pr.registration()
reg.verbose = False
reg.TestingData()

#Set up pipeline components
itk2vtk1=connect2.itk2vtk()
itk2vtk2=connect2.itk2vtk()

lut1=vtk.vtkLookupTable()
lut2=vtk.vtkLookupTable()

colors1=vtk.vtkImageMapToColors()
colors2=vtk.vtkImageMapToColors()

imageMapper1=vtk.vtkImageMapper()
imageMapper2=vtk.vtkImageMapper()

blender=vtk.vtkImageBlend()

viewer=myImageViewer.Viewer()

#Tweak the image to test misalignment
pose=(0,0,0,0,0,10)
reg.SetPose(pose)
reg.GenerateMovingImage()

#First lookup table will map to red
lut1.SetTableRange(0,3)
lut1.SetHueRange(0,0)
lut1.SetSaturationRange(0.0,1)
lut1.SetValueRange(1,1)
lut1.Build()

#Second lookup table will map to green
lut2.SetTableRange(0,3)
lut2.SetHueRange(0.33,0.33)
lut2.SetSaturationRange(0.0,1)
lut2.SetValueRange(1,1)
lut2.Build()

#Make fixed image port 0 (RED) and Moving image port 1 (GREEN)
itk2vtk1.SetInput(reg.fixedImage)
itk2vtk2.SetInput(reg.movingImage)

colors1.SetInput(itk2vtk1.GetOutput())
colors1.SetLookupTable(lut1)

colors2.SetInput(itk2vtk2.GetOutput())
colors2.SetLookupTable(lut2)

imageMapper1.SetInput(colors1.GetOutput())
imageMapper2.SetInput(colors2.GetOutput())

imageActor1=vtk.vtkActor2D()
imageActor1.SetMapper(imageMapper1)

imageActor2=vtk.vtkActor2D()
imageActor2.SetMapper(imageMapper2)

blender.SetInput(0,colors1.GetOutput())
blender.SetInput(1,colors2.GetOutput())

#set the opacity of the ports so that both images are visible
blender.SetOpacity(0,1.0)
blender.SetOpacity(1,0.7)

#Setup the image viewer
viewer.View(blender.GetOutput())
viewer.iv.SetSize(512,512)
viewer.iv.SetColorLevel(127.5)
viewer.iv.SetColorWindow(256)
